<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
      class="x-admin-sm">
<auth:data uri="/system/task/list.json"/>
<head>
    <th:block th:include="common/head::noXadmin('任务列表')"/>
    <script type="application/javascript" th:src="@{/static/js/jquery.min.js}"></script>
    <script type="application/javascript" th:src="@{/static/lib/ztree/js/jquery.ztree.all.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/static/lib/ztree/css/metroStyle/metroStyle.css}"/>
</head>
<body>
<div class="layui-row ">
    <div id="mainBox" class="layui-col-md12">
        <div class="layui-card " id="queryBox">
            <div class="layui-card-body ">
                <form class="layui-form layui-col-space5" lay-filter="searchForm">
                    <input type="hidden" id="deptId" name="deptId" th:value="${deptId==null?1:deptId}"/>
                    <div class="layui-inline layui-show-xs-block">
                        <input class="layui-input" autocomplete="off" placeholder="开始日" name="stime" id="start">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input class="layui-input" autocomplete="off" placeholder="截止日" name="etime" id="end"></div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="taskGroup" placeholder="请输入任务组" autocomplete="off"
                               class="layui-input"></div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="taskName" placeholder="请输入任务名称" autocomplete="off"
                               class="layui-input"></div>
                    <div class="layui-inline layui-show-xs-block">
                        <select name="status" lay-verify="">
                            <option value="">状态</option>
                            <option value="0"
                                    th:each="status:${T(com.hardydou.common.constant.Const.Status).values()}"
                                    th:value="${status.val}"
                                    th:text="${status.name}">
                            </option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" lay-submit="" lay-filter="sreach">
                            <i class="layui-icon">&#xe615;</i></button>
                    </div>
                </form>
            </div>

        </div>
        <div class="split-line-y split-line-y-open">
            <i class="fa "></i>
        </div>
        <div class="layui-card ">
            <div class="layui-card-body ">
                <table class="layui-table" id="dataList" lay-filter="data"></table>
            </div>
        </div>
    </div>
</div>
</body>
<th:block th:inline="none">
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
            </button>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delAll">
                <i class="layui-icon layui-icon-delete"></i>
            </button>
        </div>
    </script>
    <script type="text/html" id="statusTpl">
        <!-- 这里的checked的状态只是演示 -->
        <input type="checkbox" name="status" value="{{d.taskId}}" lay-skin="switch" lay-text="启用|停用"
               {{d.status==0?"checked":""}} lay-filter="status" disabled>
    </script>
    <script type="text/html" id="barTpl">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"
           sec:authorize="hasAuthority('system:task:info')">查看</a>
        <a class="layui-btn layui-btn-warm layui-btn-xs " lay-event="on-off"
           sec:authorize="hasAuthority('system:task:status')">{{d.status==0?"停用":"启用"}}</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit" sec:authorize="hasAuthority('system:task:edit')">编辑</a>
    </script>
    <script>
        var queryBoxShow = true;
        $(".split-line-y >i").click(function () {
            if (queryBoxShow) {
                queryBoxShow = false;
                $("#queryBox").slideUp('fast');
                $(".split-line-y").removeClass('split-line-y-open').addClass('split-line-y-closed');
            } else {
                queryBoxShow = true;
                $("#queryBox").slideDown('fast');
                $(".split-line-y").removeClass('split-line-y-closed').addClass('split-line-y-open');
            }

        });
        layui.use(['table', 'form'],
            function () {
                var table = layui.table,
                    form = layui.form;
                table.render({
                    elem: '#dataList'
                    , toolbar: '#toolbarDemo'
                    , totalRow: false
                    , url: '/system/task/list.json' //数据接口
                    , where: {stime: '', etime: '', taskName: '', taskGroup: '', orderBy: 'ctime desc'}
                    , page: true //开启分页
                    , response: {
                        statusCode: 0
                    }
                    , cols: [[
                        {checkbox: true, type: 'checkbox', fixed: 'left'}
                        , {field: 'taskId', title: 'ID', width: 80, sort: true, fixed: 'left'}
                        , {field: 'taskGroup', title: '任务组', width: 120,}
                        , {field: 'taskName', title: '任务名称', width: 100,}
                        , {field: 'taskClass', title: '执行方法', templet: '#sexTml', width: 80}
                        , {field: 'taskCron', title: '执行时间', width: 120}
                        , {field: 'taskZone', title: '参考时区', minWidth: 150}
                        , {field: 'status', title: '状态', templet: '#statusTpl', width: 100}
                        , {field: 'ctime', title: '创建时间', width: 180}
                        , {title: '操作', align: 'center', fixed: 'right', templet: '#barTpl', minWidth: 250}
                    ]],
                    parseData: function (res) {
                        return {
                            code: res.code,
                            msg: res.message,
                            count: res.data.total,
                            data: res.data.list,
                            totalRow: {
                                score: "score",
                                experience: "exp"
                            }
                        }

                    }
                    , request: {
                        pageName: 'pageNum' //页码的参数名称，默认：page
                        , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                    }
                })
                //监听工具条
                table.on('tool(data)',
                    function (obj) {
                        var data = obj.data
                            , event = obj.event //事件
                        ;
                        switch (event) {
                            case 'on-off':
                                $.ajax({
                                    url: rootPath + 'system/task/status?taskId=' + data.taskId,
                                    type: "PUT",
                                    dataType: "json",
                                    success: function (data) {
                                        layer.msg(data.message);
                                        table.reload('dataList', {
                                                page: {
                                                    curr: 1
                                                }
                                            }
                                        )
                                    },
                                    error: function (xhr, status) {
                                        layer.msg(xhr.responseJSON.message);
                                    }
                                });
                                break;
                            case 'edit':
                                xadmin.open('修改账户', rootPath + 'system/task/edit?taskId=' + data.taskId)
                                break;
                            case 'detail':
                                xadmin.open('用户详情', rootPath + 'system/task/info?taskId=' + data.taskId)
                                break;
                            case 'del':
                                layer.msg('你确定删除么？', {
                                    time: 2000,//2秒自动关闭
                                    btn: ['确定', '取消'],
                                    yes: function (index) {
                                        $.ajax({
                                            url: rootPath + 'system/task/del?taskIds=' + data.taskId,
                                            type: "DELETE",
                                            dataType: "json",
                                            success: function (data) {
                                                layer.msg(data.message);
                                                table.reload('dataList', {
                                                        page: {
                                                            curr: 1
                                                        }
                                                    }
                                                )
                                            },
                                            error: function (data) {
                                                layer.msg(data.message);
                                            }
                                        });
                                        layer.close(index);
                                    }
                                })
                                break;

                        }
                    });

                //头工具栏事件
                table.on('toolbar(data)',
                    function (obj) {
                        let checkedData = table.checkStatus('dataList').data;
                        var ids = "";
                        checkedData.forEach(function (item, idx) {
                            ids += item.userId + ",";
                        });
                        ids = ids.substr(0, ids.length - 1);
                        switch (obj.event) {
                            case 'add':
                                xadmin.open('添加任务', rootPath + 'system/task/add');
                                break;
                            case 'delAll':
                                if (ids == "") {
                                    layer.alert("请先选择任务！")
                                    return;
                                }
                                layer.msg('你确定删除么？', {
                                    time: 2000,//2秒自动关闭
                                    btn: ['确定', '取消'],
                                    yes: function (index) {
                                        $.ajax({
                                            url: rootPath + 'system/task/del?taskIds=' + ids,
                                            type: "DELETE",
                                            dataType: "json",
                                            success: function (data) {
                                                layer.msg(data.message);
                                                table.reload('dataList', {
                                                        page: {
                                                            curr: 1
                                                        }
                                                    }
                                                )
                                            },
                                            error: function (data) {
                                                layer.msg(data.message);
                                            }
                                        });
                                        layer.close(index);
                                    }
                                })
                                break;
                        }
                        ;
                    })
                ;
                form.on('submit(sreach)', function (data) {
                    table.reload('dataList', {
                            page: {
                                curr: 1
                            },
                            where: data.field
                        }
                    )
                    return false;
                })
            })
        ;

    </script>
    <script>layui.use('laydate',
        function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });

        });</script>
</th:block>
</html>